<template>
	<view class="update-count">
		<u-icon name="minus-circle-fill" color="#fc5001" size="20" @click="min"></u-icon>
		<view class="cart-count">
			{{inum}}
		</view>
		<u-icon name="plus-circle-fill" color="#fc5001" size="20" @click="add"></u-icon>
	</view>
</template>

<script>
	export default {	
		props:{
			num:{
				default:1,
				type:Number
			},
			index:Number,
		},
		watch:{
			num(n,o){
				this.inum = n
			}
		},
		data() {
			return {
				inum:1
				
			}
		},
		mounted() {
			this.inum = this.num
		},
		methods: {
			min(){
				this.inum --
				this.$emit('reduce',this.index)
			},
			add(){
				this.inum ++
				this.$emit('add',this.index)
			}
		}
	}
</script>

<style lang="scss">
	.update-count {
		display: flex;
		text-align: center;
		width: 150rpx;
		// height: 50rpx;
		justify-content: space-between;
		
		.cart-count {
			display: flex;
			align-items: center;
		}
	
	}
</style>